package com.zyf.chapter02.behavior.state.mario.refactor.v2;

/**
 * <h3>状态机</h3>
 * 状态模式:MarioStateMachine 和各个状态类之间是双向依赖关系 <br/>
 * 各个状态修改成了单例模式，状态机通过参数的方式传递给各个状态
 * @author yifeng
 */
public class MarioStateMachine {
    private int score;
    private IMario currentState; // 不再使用枚举来表示状态

    public MarioStateMachine() {
        this.score = 0;
        this.currentState = SmallMario.getInstance();
    }

    public void obtainMushRoom() {
        this.currentState.obtainMushRoom(this);
    }

    public void obtainCape() {
        this.currentState.obtainCape(this);
    }

    public void meetMonster() {
        this.currentState.meetMoster(this);
    }

    public int getScore() {
        return score;
    }

    public IMario getCurrentState() {
        return currentState;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public void setCurrentState(IMario currentState) {
        this.currentState = currentState;
    }
}
